package com.bwie.controller;

import com.bwie.common.domain.request.LoginUserRequest;
import com.bwie.common.domain.response.JwtResponse;
import com.bwie.common.result.Result;
import com.bwie.service.UserAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 用户授权校验控制层
 *
 * @author <a href="mailto:3364114353@qq.com">liuwenliang</a>
 * @version 1.0
 * @description: 用户授权校验控制层
 * @date 2025/9/9 10:04
 */
@RestController
@RequestMapping("/sysAuth")
@CrossOrigin
public class UserAuthController {

    @Autowired
    private UserAuthService userAuthService;


    /**
     * 登录
     * @param loginUserRequest
     * @return token信息
     */
    @PostMapping("/login")
    public Result<JwtResponse> doLogin (@RequestBody @Valid LoginUserRequest loginUserRequest) {
        JwtResponse jwtResponse = userAuthService.login(loginUserRequest);
        return Result.success(jwtResponse);
    }

    /**
     * 发送验证码
     * @param phone 手机号
     * @return 是否发送成功
     */
    @GetMapping("/sendCode/{phone}")
    public Result sendCode (@PathVariable("phone") String phone) {
        userAuthService.sendCode(phone);
        return Result.success();
    }
}
